//
//  YSGMyopiaEyeDegreeCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/1/6.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

class YSGMyopiaEyeDegreeCell: UITableViewCell, UITextFieldDelegate {
    
    weak var delegate: YSGMyopiaRecordCellDelegate?
    
    private var checkInfo = YSGMyopiaRecordDetailCheckInfo()

    func configure(with checkInfo: YSGMyopiaRecordDetailCheckInfo, isEdited: Bool) {
        self.checkInfo = checkInfo
        titleLabel.text = checkInfo.title
        ballTextField.text = checkInfo.ballDegree
        columnTextField.text = checkInfo.columnDegree
        axisTextField.text = checkInfo.axis
        
        ballTextField.isEnabled = !isEdited
        columnTextField.isEnabled = !isEdited
        axisTextField.isEnabled = !isEdited
    }
    
    @IBOutlet private weak var containerView: UIView! {
        didSet {
            containerView.layer.cornerRadius = 16
            containerView.setShadow()
        }
    }
    
    @IBOutlet private weak var titleLabel: UILabel!
    
    @IBOutlet private weak var ballTextField: UITextField! {
        didSet {
            ballTextField.delegate = self
        }
    }
    @IBOutlet private weak var columnTextField: UITextField! {
        didSet {
            columnTextField.delegate = self
        }
    }
    @IBOutlet private weak var axisTextField: UITextField! {
        didSet {
            axisTextField.delegate = self
        }
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        if textField == ballTextField {
            checkInfo.ballDegree = textField.text
        } else if textField == columnTextField {
            checkInfo.columnDegree = textField.text
        } else {
            checkInfo.axis = textField.text
        }
        delegate?.eyeRefractiveCell(self, checkInfo: checkInfo)
    }
}
